<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
    <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <style type="text/css">
        /* tooltip */
        #tooltip{
            position:absolute;
            border:1px solid #ccc;
            background:#333;
            padding:2px;
            display:none;
            color:#fff;
        }
    </style>
</head>
<body style="margin: 0 20px">
<fieldset class="layui-elem-field site-demo-button" style="margin-top: 30px;border:0">
    <form class="layui-form serch" action="{:url('admin/theme/themeprolist',['id'=>$theme['id']])}" method="post">
        <div class="layui-form-item" style="float: left;">
            <div class="layui-input-inline">
                <input type="text" name="goods_id" value="{if isset($wherelist['goods_id'])}{$wherelist['goods_id']}{/if}" lay-verify="title" placeholder="请输入商品id" class="layui-input layui-btn-sm">
            </div>
            <div class="layui-input-inline">
                <input type="text" name="goods_name" value="{if isset($wherelist['goods_name'])}{$wherelist['goods_name']}{/if}" lay-verify="title" placeholder="请输入商品名称" class="layui-input layui-btn-sm">
            </div>
            <button class="layui-btn layui-btn-danger layui-btn-sm" lay-submit="" lay-filter="serch">查询</button>
            <a id="reset" class="layui-btn layui-btn-sm">
                重置
            </a>
            <a id="resetSort" class="layui-btn layui-btn-sm emptySort">
                清空排序
            </a>
            <a class="layui-btn layui-btn-sm" href="/admin/theme/index">
                返回主题页
            </a>
        </div>
    </form>
</fieldset>

<table class="layui-table" lay-even="" lay-skin="row" lay-size="sm">
    <colgroup>
        <col width="15%">
        <col width="10%">
        <col width="30%">
        <col width="15%">
        <col width="10%">
        <col width="10%">
        <col width="10%">
    </colgroup>
    <thead>
    <tr>
        <th>主题名称</th>
        <th>商品ID</th>
        <th>商品名称</th>
        <th>商品图片</th>
        <th>城市</th>
        <th>排序</th>
        <th>权重操作</th>
    </tr>
    </thead>
    <tbody>
    {volist name="info" id="vo"}
    <tr style="height:100px;">
        <td style="text-align:center;">{$theme.name}</td>
        <td style="text-align:center;">{$vo.goods_id}</td>
        <td>{$vo.goods_name}</td>
        <td><img src="{$vo.goods_image}" alt=""></td>
        <td>{$vo.city_name}</td>
        <td>{$key = array_search($vo.goods_id,$sort)}{if $key===false}-1{/if}</td>
        <td style="text-align:center;">
            <button class="layui-btn layui-btn-danger layui-btn-sm toTop" lay-submit="" lay-filter="serch" data-id="{$vo.goods_id}">置顶</button>
        </td>
    </tr>
    {/volist}
    </tbody>
</table>
<div style="padding:0 20px;">{$info->render()}</div>

<script src="__PUBLIC__/layui/layui.js" charset="utf-8"></script>
<script src="__PUBLIC__/jquery/jquery.min.js"></script>
<script>
    var message;
    layui.config({
        base: '__JS__/',
        version: '1.0.1'
    }).use(['app', 'message'], function() {
        var app = layui.app,
            $ = layui.jquery,
            layer = layui.layer;
        //将message设置为全局以便子页面调用
        message = layui.message;
        //主入口
        app.set({
            type: 'iframe'
        }).init();
    });
</script>
<script type="text/javascript">
    var themeid = {$theme.id};
    $('.toTop').click(function(){
        var id = $(this).attr('data-id');
        layer.confirm('确定要置顶吗?', function(index) {
            var index = layer.load(1);
            $.ajax({
                url:"{:url('admin/theme/sortThemeGoods')}",
                data:{
                    theme_id:themeid,
                    goods_id:id
                },
                dataType:"JSON",
                type:"POST",
                success:function(res) {
                    layer.close(index);
                    layer.msg(res.msg);
                    if(res.code == 200) {
                        setTimeout(function(){
                            window.location.reload();
                        },1500)
                    }
                }
            })
        })
    })


    $('.emptySort').click(function(){
        layer.confirm('确定要清空排序吗?', function(index) {
            var index = layer.load(1);
            $.ajax({
                url:"{:url('admin/theme/emptySort')}",
                data:{
                    theme_id:themeid
                },
                type:"POST",
                dataType:"JSON",
                success:function(res) {
                    layer.close(index);
                    layer.msg(res.msg);
                    if(res.code == 200) {
                        setTimeout(function(){
                            window.location.reload();
                        },1500)
                    }
                }
            })
        })
    })


</script>
<script type="text/javascript">
    layui.use('layer', function(){
        var layer = layui.layer;
        $('.a_menu').click(function(){
            var url = $(this).attr('href');
            var a = 0;
            $.ajax({
                url:url
                ,async:false
                ,success:function(res){
                    if(res.code == 0) {
                        layer.msg(res.msg);
                        a = 1;
                    }
                }
            })
            if(a === 0) {
                layer.open({
                    type:2,
                    content:[url],
                    area: ['900px', '700px'],
                    end:function(){
                        location.reload();
                    }
                });
            }
            return false;
        })

        $("#reset").click(function(){
            $("input[name=goods_id]").val("");
            $("input[name=goods_name]").val("");
        })
    });
</script>
</body>
</html>
